<?php
	session_start();
	
	if (!isset($_SESSION['sesi_login']))
		header("Location:../../index.php");
		
	@chdir("../../");
	define('ABS_URL',str_replace("\\","/",getcwd()));
	require ABS_URL.'/engine/Smarty.class.php';
	require ABS_URL."/functions/class.query.inc.php";
	$smarty = new Smarty();
	require ABS_URL."/dev_con.inc.php";
	require ABS_URL."/functions/func_file.php";
	$queryData = new queryData();
	$queryData->baseConfig();
	require ABS_URL."/functions/func_content.php";
	require ABS_URL."/langs/".BASE_LANGUAGE.'.inc.php';
	require ABS_URL."/functions/class.sitemap.inc.php";
	require $queryData->get_curr_dir(dirname(__FILE__))."/langs/".BASE_LANGUAGE.'.inc.php';
	
	if ($_POST['submit']) {
			$tipe = "";
		if ($_POST['kategori']) {
			foreach ($_POST['kategori'] as $val) {
				$tipe .= "tipe='".$val."' OR ";	
			}
			
			if (trim($_POST['yahoo_app_id'])!="")
				$yahoo_app_id = strip_tags(trim($_POST['yahoo_app_id']));
			
			$tipe = substr($tipe,0,-4);
			
			if ($_POST['include_page']=="yes")
				$tipe .= " OR tipe LIKE 'dinamis%'";
			
			$time = explode(" ",microtime());
			$time = $time[1];
			
			(defined("USE_REWRITE")) ? $file = USE_REWRITE : $file = 'index.php';
			$sitemap = new SitemapGenerator("http://".$_SERVER['HTTP_HOST']."/","../../");
	
			$sql = "SELECT * FROM tbl_content WHERE ".$tipe." AND status='1' ORDER BY tanggal DESC LIMIT 0, 5";
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				(($row->tipe=='artikel') || ($row->tipe=='berita')) ? $page = "detail" : $page = "dinamis";
				$sitemap->addUrl("http://".$_SERVER['HTTP_HOST']."/".$file."/1/".$page."/".$row->idx."/".$queryData->permalink($row->idx)."/",$queryData->tanggalan($row->tanggal,false,false,false,false,true),'daily','1.0');
			}
	
			$sql = "SELECT * FROM tbl_content WHERE ".$tipe." AND status='1' ORDER BY tanggal DESC LIMIT 6, 10";
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				(($row->tipe=='artikel') || ($row->tipe=='berita')) ? $page = "detail" : $page = "dinamis";
				$sitemap->addUrl("http://".$_SERVER['HTTP_HOST']."/".$file."/1/".$page."/".$row->idx."/".$queryData->permalink($row->idx)."/",$queryData->tanggalan($row->tanggal,false,false,false,false,true),'weekly','0.9');
			}
			
			$sql = "SELECT * FROM tbl_content WHERE ".$tipe." AND status='1' ORDER BY tanggal DESC LIMIT 11,20";
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				(($row->tipe=='artikel') || ($row->tipe=='berita')) ? $page = "detail" : $page = "dinamis";
				$sitemap->addUrl("http://".$_SERVER['HTTP_HOST']."/".$file."/1/".$page."/".$row->idx."/".$queryData->permalink($row->idx)."/",$queryData->tanggalan($row->tanggal,false,false,false,false,true),'weekly','0.8');
			}
			
			$sql = "SELECT * FROM tbl_content WHERE ".$tipe." AND status='1' ORDER BY tanggal DESC LIMIT 21,30";
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				(($row->tipe=='artikel') || ($row->tipe=='berita')) ? $page = "detail" : $page = "dinamis";
				$sitemap->addUrl("http://".$_SERVER['HTTP_HOST']."/".$file."/1/".$page."/".$row->idx."/".$queryData->permalink($row->idx)."/",$queryData->tanggalan($row->tanggal,false,false,false,false,true),'monthly','0.7');
			}
			
			$sql = "SELECT * FROM tbl_content WHERE ".$tipe." AND status='1' ORDER BY tanggal DESC LIMIT 31,40";
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				(($row->tipe=='artikel') || ($row->tipe=='berita')) ? $page = "detail" : $page = "dinamis";
				$sitemap->addUrl("http://".$_SERVER['HTTP_HOST']."/".$file."/1/".$page."/".$row->idx."/".$queryData->permalink($row->idx)."/",$queryData->tanggalan($row->tanggal,false,false,false,false,true),'monthly','0.6');
			}
			
			$sql = "SELECT * FROM tbl_content WHERE ".$tipe." AND status='1' ORDER BY tanggal DESC LIMIT 41,50";
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				(($row->tipe=='artikel') || ($row->tipe=='berita')) ? $page = "detail" : $page = "dinamis";
				$sitemap->addUrl("http://".$_SERVER['HTTP_HOST']."/".$file."/1/".$page."/".$row->idx."/".$queryData->permalink($row->idx)."/",$queryData->tanggalan($row->tanggal,false,false,false,false,true),'monthly','0.5');
			}
			
			$sql = "SELECT idx FROM tbl_content WHERE ".$tipe." AND status='1'";
			$qry = mysql_query($sql);
			$num = mysql_num_rows($qry);
			
			$sql = "SELECT * FROM tbl_content WHERE ".$tipe." AND status='1' ORDER BY tanggal DESC LIMIT 51,".$num;
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				(($row->tipe=='artikel') || ($row->tipe=='berita')) ? $page = "detail" : $page = "dinamis";
				$sitemap->addUrl("http://".$_SERVER['HTTP_HOST']."/".$file."/1/".$page."/".$row->idx."/".$queryData->permalink($row->idx)."/",$queryData->tanggalan($row->tanggal,false,false,false,false,true),'yearly','0.4');
			}
			
			try {
				$sitemap->buatSitemap();
				$sitemap->tulisSitemap();
				$sitemap->ubahRobots();
				$result = $sitemap->kirimSitemap($yahoo_app_id);
				
				$_SESSION['sesi_ver'] = $SITEMAP_SUCCESS;
				
			} catch (Exception $e) {
				$_SESSION['sesi_ver'] = $SITEMAP_ERROR.$e->getMessage()."\n";	
			}
			
		}
	}
	
	if (isset($_SESSION['sesi_login'])) {
		header('Location:../../?show='.SHOW.'&showview='.SHOWVIEW.'&act='.$act.'&limitdown=0');
	} else {
		header("Location:../../index.php");
	};
?>